<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #wrap{
            display: flex;
        }
        .title_header{
            width: 300px;
            height: 100vh;
            background-color: #20222A;
            display: flex;
            justify-content: flex-end;
        }
        .title_header .active_header{
            width: 5px;
            height: 100%;
            background-color: antiquewhite;
            transition:all 0.5s;
        }
        .ulli{
            width: 100%;
            height: 100%;
            padding: 0;
            text-align: center;
            color:white;
            list-style-type: none;
        }
        .content{
            flex:1;
            height: 100vh;
            background-color: #F2F2F2;
            padding: 10px
        }
        .content div{
            border-radius: 5px;
        }
        .content .top_header{
            width: 100%;
            background-color: #fff;
            padding: 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-sizing: border-box;
            font-size: 12px;
        }
        .content-content{
            display: flex;
            gap: 20px;
            overflow: hidden;
            margin: 20px 0;
            height: 60%;
        }
        .content-content .content-left{
            width: 60%;
            height: 100%;
            background-color: #fff;
            font-size: 40px;
            font-weight: 600;
            display: grid;
            /* 水平垂直居中 */
            place-items: center;
        }
        .content-content .content-right{
            width: 40%;
            height: 100%;
            background-color: #fff;
            font-size: 40px;
            font-weight: 600;
            display: grid;
            /* 水平垂直居中 */
            place-items: center;
        }
        .floor{
            width: 100%;
            height: 30%;
            background-color: #fff;
            font-size: 40px;
            font-weight: 600;
            display: grid;
            /* 水平垂直居中 */
            place-items: center; 
        }
        .btn-parmary{
            --color:rgba(0, 145, 255,0.9);
            padding: 10px 20px;
            background-color: var(--color);
            color:white;
            font-weight: 600;
            border: transparent;
            outline: none;
            cursor: pointer;
            border-radius: 5px;
        }
        .btn-parmary:hover{
            background-color: rgb(from var(--color) r g b / calc(alpha - .5));
        }
        .btn-parmary:active{
            background-color: rgb(from var(--color) r g b / calc(alpha - .4));
        }
        .content-body{
            width: 100%;
        }
        .content-body table{
            width: inherit;
            margin: 10px 0;
            border-collapse: collapse;
        }
        .content-body table td{
            border: 3px solid #ccc;
            padding: 10px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div id="wrap">
        <div class="title_header">
            <ul class="ulli">
                <li>会议</li>
            </ul>
            <div class="active_header">
                 
            </div>
        </div>
        <div class="content">
            <div class="top_header">
                <div>
                    首页 > 一级菜单 > 二级菜单
                </div>
                <div style="cursor: pointer;">
                    退出登录
                </div>
            </div>
            <div style="text-align: right;margin: 10px;">
                <button class="btn-parmary" onclick="window.open('add.html','_blank')">新增</button>
            </div>
           
            <div class="content-content">
                <div class="content-body">
                    <table>
                        <thead>
                            <tr>
                                <td>uid</td>
                                <td>name</td>
                                <td>sex</td>
                                <td>age</td>
                                <td>成绩</td>
                                <td>相比之差多少</td>
                                <td>相比之高多少</td>
                            </tr>
                        </thead>
                        <tbody id="append_data">
                            
                        </tbody>
                    </table>
                </div>
            </div>
            <!-- <div class="floor">
                
            </div> -->
        </div>
    </div>
</body>
</html>
<script>
    var title_header = document.querySelector(".title_header")
    var active_header = document.querySelector(".active_header")
    var append_data = document.getElementById("append_data")
    var channel = new BroadcastChannel('myChannel');
    var body = document.body;
    //鼠标移入
    const mousemove = ()=>{
        active_header.style.width = "10px"
        active_header.style.cursor = "e-resize"
        active_header.style.backgroundColor="skyblue";
    }

    //鼠标移出
    const mouseleaves = ()=>{
        active_header.style.width="5px"
        active_header.style.cursor = "default"
        active_header.style.backgroundColor = "antiquewhite"
    }

    //鼠标按下
    const clicksdown = (e)=>{
        body.addEventListener("mousemove",mouseenters)
        mousemove()
        active_header.removeEventListener("mouseleave",mouseleaves)
        //鼠标抬起为保证性能不行最好把dom改成body
        body.addEventListener("mouseup",clicksup)
    }
    var x = null
    //鼠标移入
    const mouseenters = (e)=>{
        var x = e.clientX
        if(x<=100){
            x = 100
        }
        title_header.style.width=`${ x }px`
    }

    //鼠标抬起
    const clicksup = (e)=>{
        console.log("鼠标抬起")
        mousemove()
        active_header.addEventListener("mouseleave",mouseleaves)
        body.removeEventListener("mousemove",mouseenters)
        body.removeEventListener("mouseup",clicksup)
    }

    active_header.addEventListener("mouseenter",mousemove)
    active_header.addEventListener("mouseleave",mouseleaves)
    active_header.addEventListener("mousedown",clicksdown)
    
    function req(url,method){
        return new Promise((res,rej)=>{
            var xhr = new XMLHttpRequest();
            var datalist = null
            xhr.open(method, "http://127.0.0.1:3000" + url , false);
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    res(xhr.responseText)
                }
            };
            xhr.send();
        })
    }
    
    function getdata(){
        req("/getdata","GET").then(res=>{
            var res = JSON.parse(res)
            console.log(res.data)
            var str = ""
            res.data.forEach((item,index)=>{
                str+=`
                <tr>
                    <td>${item.uid}</td>
                    <td>${item.name}</td>
                    <td>${item.sex}</td>
                    <td>${item.age}</td>
                    <td>${item.cheng}</td>
                    <td>${item.thin}</td>
                    <td>${item.tall}</td>
                </tr>
                `
            })
            append_data.innerHTML = `
            <tbody>
                ${ str }
            </tbody>
            `
        })
    }

    getdata()

    
    channel.onmessage = (event) =>{
        getdata()
    }
</script>